package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.BieHouse;
import com.ruoyi.system.domain.BieHouseholder;
import com.ruoyi.system.mapper.BieHouseMapper;
import com.ruoyi.system.mapper.BieHouseholderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BieAccessCardMapper;
import com.ruoyi.system.domain.BieAccessCard;
import com.ruoyi.system.service.IBieAccessCardService;

/**
 * 门禁卡Service业务层处理
 * 
 * @author zxl
 * @date 2021-05-03
 */
@Service
public class BieAccessCardServiceImpl implements IBieAccessCardService 
{
    @Autowired
    private BieAccessCardMapper bieAccessCardMapper;

    @Autowired
    private BieHouseholderServiceImpl bieHouseholderService;

    @Autowired
    private BieHouseServiceImpl bieHouseService;
    /**
     * 查询门禁卡
     * 
     * @param accessCardId 门禁卡ID
     * @return 门禁卡
     */
    @Override
    public BieAccessCard selectBieAccessCardById(String accessCardId)
    {
        return bieAccessCardMapper.selectBieAccessCardById(accessCardId);
    }

    /**
     * 查询门禁卡列表
     * 
     * @param bieAccessCard 门禁卡
     * @return 门禁卡
     */
    @Override
    public List<BieAccessCard> selectBieAccessCardList(BieAccessCard bieAccessCard)
    {
        return bieAccessCardMapper.selectBieAccessCardList(bieAccessCard);
    }

    /**
     * 新增门禁卡
     * 
     * @param bieAccessCard 门禁卡
     * @return 结果
     */
    @Override
    public int insertBieAccessCard(BieAccessCard bieAccessCard)
    {
        bieAccessCard.setAccessCardId(UUID.randomUUID().toString());
        bieAccessCard.setCreateTime(DateUtils.getNowDate());
        //查询房子信息
        String houseId = bieAccessCard.getHouseId();
        BieHouse bieHouse = bieHouseService.selectBieHouseById(houseId);
        bieAccessCard.setVllageName(bieHouse.getVillageName());
        bieAccessCard.setBuildingNum(bieHouse.getBuildingNum());
        bieAccessCard.setFloorNum(bieHouse.getFloorNum());
        bieAccessCard.setUnitNum(bieHouse.getUnitNum());
        bieAccessCard.setRoomNum(bieHouse.getRoomNum());
        //查询住户信息
        String holderId = bieAccessCard.getHolderId();
        BieHouseholder bieHouseholder = bieHouseholderService.selectBieHouseholderById(holderId);
        bieAccessCard.setHolderName(bieHouseholder.getHolderName());
        bieAccessCard.setPhone(bieHouseholder.getPhone());

        //System.out.println(bieAccessCard);
        return bieAccessCardMapper.insertBieAccessCard(bieAccessCard);
    }

    /**
     * 修改门禁卡
     * 
     * @param bieAccessCard 门禁卡
     * @return 结果
     */
    @Override
    public int updateBieAccessCard(BieAccessCard bieAccessCard)
    {
        bieAccessCard.setUpdateTime(DateUtils.getNowDate());
        return bieAccessCardMapper.updateBieAccessCard(bieAccessCard);
    }

    /**
     * 批量删除门禁卡
     * 
     * @param accessCardIds 需要删除的门禁卡ID
     * @return 结果
     */
    @Override
    public int deleteBieAccessCardByIds(String[] accessCardIds)
    {
        return bieAccessCardMapper.deleteBieAccessCardByIds(accessCardIds);
    }

    /**
     * 删除门禁卡信息
     * 
     * @param accessCardId 门禁卡ID
     * @return 结果
     */
    @Override
    public int deleteBieAccessCardById(String accessCardId)
    {
        return bieAccessCardMapper.deleteBieAccessCardById(accessCardId);
    }
}
